package cn.tedu.baidashi.controller;

import cn.tedu.baidashi.service.IUserService;
import cn.tedu.baidashi.vo.RegisterVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
public class SystemController {

    @Autowired
    private IUserService userService;

    //处理注册请求
    @PostMapping("/register")
    public String register(
            //验证登录信息
            @Validated RegisterVO registerVO, BindingResult result
            ){
            log.debug("接收到的表单信息:{}",registerVO);
            if(result.hasErrors()){
                return result.getFieldError().getDefaultMessage();
            }
            userService.registerGuest(registerVO);
            return "ok";
    }

}
